﻿using System;
using System.Linq;
using BO.Infrastructure.StaticData;
using BO.Infrastructure.Utils;
using BO.News;
using BO.Photo;
using GUI.Extensions;
using System.Data;

namespace GUI.Pages.Photo
{
    public partial class Index : System.Web.UI.Page
    {
        private const int TopOther = 6;
        private const int Top = 100;

        protected void Page_Load(object sender, EventArgs e)
        {
            var newsId = RequestExtensions.NewsId;
            var newsBo = NewsBO.GetInstance();

            if (newsId <= 0)
            {
                var dt = newsBo.GetNewsByType(1, DefinedConstants.News.Types.PhotoNews, 0);
                if (dt != null && dt.Rows.Count > 0)
                {
                    long.TryParse(dt.Rows[0][SqlConstants.NewsPublish.Id].ToString(), out newsId);
                }
            }
            if (newsId > 0)
            {

                var bo = PhotoBO.GetInstance();

                #region NewsDetails
                {
                    var dt = bo.GetPhotosInNews(newsId, Top);
                    ctrHighlightPhoto.Visible = ctrHighlightPhoto.DataBind(dt);
                }
                #endregion


                #region Other PhotoNews
                {
                    var dt = newsBo.GetNewsByType(top: TopOther + 1, type: DefinedConstants.News.Types.PhotoNews, zoneId: 0);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        foreach (var r in from DataRow r in dt.Rows where (long)r[SqlConstants.NewsPublish.Id] == newsId select r)
                        {
                            dt.Rows.Remove(r);
                            break;
                        }
                    }
                    ctrOtherPhotos.Visible = ctrOtherPhotos.DataBind(dt);
                }
                #endregion
                

                //return;
            }
            else
            {
                ctrHighlightPhoto.Visible = ctrOtherPhotos.Visible = false;
            }

            #region Css/Js
            {
                PresentationUtils.AddCss(Page, Combres.WebExtensions.CombresUrl(DefinedConstants.CombresResouceSet.Css.ListSportNews));
                PresentationUtils.AddJs(Page, Combres.WebExtensions.CombresUrl(DefinedConstants.CombresResouceSet.Js.ListSportNews));
            }
            #endregion
            //_301Redirection.RedirectToFileNotFoundPage();
        }
    }
}